#include "../../inc/skyCanvas.h"

#ifdef _SYMBIAN

#include "../../inc/skyPict.h"

namespace Sky
{
	Bool Canvas::create(i32 w,i32 h,i32 format,u32 subFormat)
	{
		::Size size(w,h);
		xAssert(_pict == vNull);
		
		_pict = new Pict();
		xAssert(_pict);
		if(_pict == vNull)return vFalse;
		
		_pict->_bitmap = new CFbsBitmap;
		xAssert(_pict->_bitmap);
		if(_pict->_bitmap == vNull)return vFalse;
		
		u32 tFormat = format;
		switch(format)
		{
		case Format_Default:
			tFormat =	EColor16M;
			break;
		defualt:
			tFormat = format;
			break;
		}
		xAssert(KErrNone ==_pict->_bitmap->Create(size, (TDisplayMode)tFormat));
		//mType = Type_Create;
		if(subFormat != 0)
		{
			_pict->_bitmapMask = new CFbsBitmap;
			xAssert(_pict->_bitmapMask);
			if(_pict->_bitmapMask == vNull)
			{
				//mType = Type_CreateWitMask;
				SAFE_DELETE(_pict->_bitmap);
				SAFE_DELETE(_pict);
				return vFalse;
			}
			_pict->_bitmapMask->Create(size,(TDisplayMode)subFormat);
		}
		return vTrue;
	}
	Void  Canvas::Delete()
	{
		SAFE_DELETE(_pict);
	};

    Sky::Bool Canvas::attachPict( Pict* pict )
    {
        SAFE_DELETE(_pict);
        _pict = pict;
    }

    Sky::Pict* Canvas::detachPict()
    {
        Pict* p = _pict;
        _pict = vNull;
        return p;
    }
}
#endif
